<?php
require_once 'phpmoko/lib/common.php';

require_once 'phpmoko/ui/Form/FormBase.php';
require_once 'phpmoko/ui/Label.php';

class CheckBox extends FormBase
{
	/**
	 *
	 * @var Label
	 */
	private $label;
	private $enabled = true;
	private $value = 'Y';
	private $checked = false;

	function __construct($label)
	{
		parent::__construct();

		$this->label = new Label($label);
		$this->label->setLinkedWidget($this);

		$this->setStyleName('pmk-CheckBox');
	}

	/**
	 * Sets the checkbox whether is enabled or not
	 *
	 * @param bool $enabled
	 */
	function setEnabled($enabled)
	{
		$this->enabled = $enabled;
	}

	/**
	 * Sets the input element name
	 *
	 * @param <type> $name
	 */
	function setName($name)
	{
		$this->name = $name;
	}

	function setValue($value)
	{
		$this->value = $value;
	}

	function setChecked($value)
	{
		$this->checked = $value;
	}

	function toString()
	{
		$str = '<span';

		if ($this->style != null)
			$str .= ' class="' . $this->style;

		if (!$this->enabled)
			$str .= ' pmk-CheckBox-disabled';

		$str .= '">';

		$str .= '<input';

		$str .= ' value="' . $this->value . '"';
		if ($this->checked)
			$str .= ' checked';

		if (!$this->enabled)
			$str .= ' disabled="disabled"';

		if ($this->name != null)
			$str .= ' name="' . $this->name . '"';

		$str .= ' id="' . $this->id . '"';
		$str .= ' type="checkbox"';
		$str .= '>';

		$str .= $this->label->toString();

		$str .= '</span>';

		return $str;
	}
}
?>